package com.github.prontera.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.prontera.ApiVersion;
import com.github.prontera.common.filter.CurrentUserId;
import com.github.prontera.domain.OrderRefund;
import com.github.prontera.model.response.ObjectDataResponse;
import com.github.prontera.service.OrderRefundService;
import com.github.prontera.util.Page;

import io.swagger.annotations.ApiOperation;

/**
 * 退款管理
 * @author Mengxiangdong
 */
@RestController
@RequestMapping(value = ApiVersion.MANAGE_V1_PREFIX + "/refund", produces = { MediaType.APPLICATION_JSON_UTF8_VALUE }, consumes = { MediaType.APPLICATION_JSON_UTF8_VALUE })
public class RefundController {
	
	@Autowired
	private OrderRefundService orderRefundService;

	@ApiOperation(value = "查询退款列表", notes = "查询退款列表")
	@RequestMapping(value = "/queryRefund", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<OrderRefund>> queryRole(@RequestBody OrderRefund orderRefund) {
		Page<OrderRefund> datas = orderRefundService.page(orderRefund);
		return new ObjectDataResponse<Page<OrderRefund>>(datas);
	}

	@ApiOperation(value = "退款处理", notes = "退款处理")
	@RequestMapping(value = "/refund", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Boolean> refund(@CurrentUserId Long userId, @RequestBody OrderRefund orderRefund) {
		OrderRefund orderRefund2=orderRefundService.get(orderRefund.getId());
		orderRefund2.setStatus(orderRefund.getStatus());
		return new ObjectDataResponse<Boolean>(orderRefundService.refundOrder(orderRefund2));
	}

}
